<template>
  <div style="margin: 20px">
    <el-form :inline="true" :model="formInline" class="form-inline">
      <el-form-item label="工号">
        <el-input v-model="formInline.jobNumber" placeholder="请输入完整的工号" clearable/>
      </el-form-item>
      <el-form-item label="身份证号">
        <el-input v-model="formInline.userIdNumber" placeholder="请输入完整的身份证号码" clearable/>
      </el-form-item>
      <el-form-item label="姓名">
        <el-input v-model="formInline.userName" placeholder="根据姓名模糊查询" clearable/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="querySubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" v-loading="tableLoading" stripe style="width: 100%; height: 80%">
      <el-table-column type="index" label="序号" width="80"/>
      <el-table-column prop="deptName" label="部门" :show-overflow-tooltip="true"/>
      <el-table-column prop="userName" label="姓名" width="100"/>
      <el-table-column prop="userIdNumber" label="身份证" width="200"/>
      <el-table-column prop="jobNumber" label="工号" width="150"/>
      <el-table-column prop="userSex" label="性别" width="80"/>
      <el-table-column prop="userCategory" label="身份类别" width="100"/>
      <el-table-column prop="highestEducation" label="最高学历" width="80"/>
      <el-table-column prop="graduationTime" label="毕业时间" width="150"/>
      <el-table-column label="操作" width="200">
        <template #default="scope">
          <el-button size="small" type="primary" @click="handleDetail(scope.$index, scope.row)">
            起薪
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="demo-pagination-block">
      <el-pagination
          v-model:current-page="currentPage"
          v-model:page-size="pageSize"
          :page-sizes="[10, 20, 50, 100]"
          layout="total, sizes, prev, pager, next"
          v-model:total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script lang="ts" setup>
import {ref, onMounted, reactive} from 'vue';
import {ElMessage, ElMessageBox} from 'element-plus'
import Salary from '@/api/Salary.js';
import { useRouter } from 'vue-router'
const router = useRouter()


// 分页
const currentPage = ref(1)
const pageSize = ref(10)
const total = ref(0)
const handleSizeChange = (val: number) => {
  formInline.pageSize = val;
  getTableData(formInline)
}
const handleCurrentChange = (val: number) => {
  formInline.pageNo = val;
  getTableData(formInline)
}


// 查询条件表单
const formInline = reactive({
  pageNo: currentPage.value,
  pageSize: pageSize.value,
  jobNumber: '',
  userIdNumber: '',
  userName: '',
})
const querySubmit = () => {
  getTableData(formInline)
}


// 表格
const tableLoading = ref(false)
const tableData = ref([]);
const getTableData = (data) => {
  tableLoading.value = true
  Salary.listUserNoSalary(data)
      .then(res => {
        currentPage.value = res.data.pageNo
        pageSize.value = res.data.pageSize
        total.value = res.data.recordsTotal
        tableData.value = res.data.rows
        tableLoading.value = false
      })
      .catch(error => {
        tableLoading.value = false
      })
};
const handleDetail = (index, row) => {
  const id = row.id;
  router.push({ name: 'salaryAdd', query: { userId:id } });
}


// 钩子函数
onMounted(() => {
  getTableData(formInline)
});


</script>

<style scoped>
.form-inline {
  margin: 20px;
}
.form-inline .el-input {
  --el-input-width: 200px;
}
</style>